package com.app.view.component.resource 
{
	import com.peachcastle.events.LoaderEvent;
	import com.peachcastle.net.QueueLoader;
	import flash.display.DisplayObjectContainer;
	import flash.display.Loader;
	import flash.events.Event;
	import flash.utils.Dictionary;

	public class ResourceManager
	{
		protected static var instance : ResourceManager;
		
		private var _connection:Dictionary = null;
		
		public function ResourceManager() 
		{
			_connection = new Dictionary();
		}
		
		public function LoaderObjects(ary:Array):Resourecs
		{
			var index:int = 0;
			var count:int = ary.length;
			
			var resoures:Resourecs = new Resourecs(count);
			
			for each(var obj:Object in ary)
			{
				_connection[obj.uid + obj.type] = resoures.addResourec(obj);
			}
			
			return resoures;
		}
		
		public function addObjectLoader(uid:int, type:String, url:String, scale:int = 50, dir:int = 0):Loader
		{
			var data:ResourceData = new ResourceData();
			data.uid = uid;
			data.type = type;
			data.url = url;
			data.dir = dir;
			data.scale = scale;
			data.start();
			_connection[uid + type] = data;
			
			return data.loader;
		}
		
		
		
		public function addObject(uid:int, type:String, url:String,con:DisplayObjectContainer = null,scale:int=50):void
		{
			var data:ResourceData = new ResourceData();
			data.uid = uid;
			data.type = type;
			data.url = url;
			data.container = con;
			data.scale = scale;
			data.start();
			_connection[uid + type] = data;
		}
		
		public function hasObject(uid:int, type:String):Boolean
		{
			if (_connection[uid + type]!=null) return true;
			return false;
		}
		
		public function getObject(uid:int, type:String,show:Boolean = false,con:DisplayObjectContainer = null,scale:int=50):void
		{
			var data:ResourceData = ResourceData(_connection[uid + type]);
			data.isShow = show;
			data.container =con;
			data.scale = scale;
			data.getState();
		}
		
		
		
		public function getObjectLoader(uid:int, type:String):Loader
		{
			var data:ResourceData = ResourceData(_connection[uid + type]);
			if (data == null) return null;
			
			return data.loader;
		}
		
		public static function getInstance():ResourceManager
		{
			if (instance == null)
				instance = new ResourceManager();
				
			return instance as ResourceManager;
		}
	}
}